package com.aplink.generic.xmlparser.ctrlformat;

import org.w3c.dom.Node;

import android.text.TextUtils;

import com.aplink.generic.constant.type.DateTimePickerType;
import com.aplink.generic.pojo.controlspec.DateTimePickerSpec;
import com.aplink.generic.xmlparser.XMLPaserUtil;

public class DateTimeFormat {
    public static final String DATE_VALUE_CONTROL = "dateValueControl";
    public static final String DISPLAY_FORMAT = "displayFormat";
    public static final String FULL_VALUE_CONTROL = "fullValueControl";
    public static final String IS_24_HOUR = "is24Hour";
    public static final String PICKER_MODE = "mode";
    public static final String TIME_VALUE_CONTROL = "timeValueControl";

    public static DateTimePickerSpec parse(final Node node) {
        final DateTimePickerSpec dateTimePickerSpec = new DateTimePickerSpec();
        if (node.hasAttributes()) {
            String value = XMLPaserUtil.getAttrValue(node,
                    DateTimeFormat.FULL_VALUE_CONTROL);
            if (!TextUtils.isEmpty(value)) {
                dateTimePickerSpec.setFullValueControl(value);
            }

            value = XMLPaserUtil.getAttrValue(node,
                    DateTimeFormat.DATE_VALUE_CONTROL);
            if (!TextUtils.isEmpty(value)) {
                dateTimePickerSpec.setDateValueControl(value);
            }

            value = XMLPaserUtil.getAttrValue(node,
                    DateTimeFormat.TIME_VALUE_CONTROL);
            if (!TextUtils.isEmpty(value)) {
                dateTimePickerSpec.setTimeValueControl(value);
            }

            value = XMLPaserUtil.getAttrValue(node,
                    DateTimeFormat.DISPLAY_FORMAT);
            if (!TextUtils.isEmpty(value)) {
                dateTimePickerSpec.setDisplayFormat(value);
            }

            value = XMLPaserUtil.getAttrValue(node, DateTimeFormat.IS_24_HOUR);
            if (!TextUtils.isEmpty(value)) {
                if (value.equalsIgnoreCase("Y")) {
                    dateTimePickerSpec.setIs24Hour(true);
                }
            }
            value = XMLPaserUtil.getAttrValue(node, DateTimeFormat.PICKER_MODE);
            if (!TextUtils.isEmpty(value)) {
                dateTimePickerSpec.setDateTimePickerType(DateTimePickerType
                        .get(value));
            }
        }
        return dateTimePickerSpec;
    }
}
